package org.seedltd.upms.controller.detection;

import java.util.List;
import java.util.Map;

import org.seedltd.core.base.BaseController;
import org.seedltd.core.base.BasePage;
import org.seedltd.core.utils.Assert;
import org.seedltd.core.validation.Save;
import org.seedltd.core.validation.Update;
import org.seedltd.log.annotation.SysLog;
import org.seedltd.upms.model.detection.form.DetectionProductItemForm;
import org.seedltd.upms.model.detection.form.DetectionProductItemSearchForm;
import org.seedltd.upms.model.detection.vo.DetectionProductItemVO;
import org.seedltd.upms.service.detection.DetectionProductItemService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import lombok.AllArgsConstructor;

/**
 *
 * 产品检测项控制器
 * 
 * @author laizuan
 * @version 1.0
 * @since 2021/08/25
 */
@RestController
@AllArgsConstructor
@RequestMapping("/detectionProductItem")
public class DetectionProductItemController extends BaseController<DetectionProductItemService> {

    /**
     * 新增
     * 
     * @param form
     *            产品检测项表单数据
     * @return 产品检测项主键
     */
    @SysLog("新增产品检测项")
    @PostMapping(value = "/add")
    @PreAuthorize("hasAuthority('detection:productItem:add')")
    public Long add(@RequestBody @Validated({Save.class}) DetectionProductItemForm form) {
        return baseService.add(form);
    }

    /**
     * 获取详情
     * 
     * @param id
     *            产品检测项主键
     * @return 产品检测项
     */
    @GetMapping(value = "/get")
    public DetectionProductItemVO get(Long id) {
        Assert.notNull(id, "参数不能为空");
        return baseService.findById(id);
    }

    /**
     * 修改
     * 
     * @param form
     *            产品检测项表单数据
     * @return 修改状态。true标识修改成功，false标识修改失败
     */
    @SysLog("修改产品检测项")
    @PostMapping(value = "/update")
    @PreAuthorize("hasAuthority('detection:productItem:update')")
    public boolean update(@RequestBody @Validated({Update.class, Save.class}) DetectionProductItemForm form) {
        return baseService.update(form);
    }

    /**
     * 删除
     * 
     * @param id
     *            产品检测项主键
     * @return 删除状态。true标识修改成功，false标识修改失败
     */
    @SysLog("删除产品检测项")
    @GetMapping(value = "/delete")
    @PreAuthorize("hasAuthority('detection:productItem:delete')")
    public boolean delete(Long id) {
        Assert.notNull(id, "ID不能为空");
        return baseService.delete(id);
    }

    /**
     * 列表
     * 
     * @param searchForm
     *            查询条件
     * @return 产品检测项列表集合
     */
    @PostMapping(value = "/list")
    public BasePage<DetectionProductItemVO> page(@RequestBody DetectionProductItemSearchForm searchForm) {
        return baseService.page(searchForm);
    }

    /**
     * 查询所有数据
     * 
     * @return 产品检测项列表集合
     */
    @GetMapping(value = "/listAll")
    public List<Map<String, Object>> listAll() {
        return baseService.listAll();
    }

}